package chapter04

/**
 * @program lu-scala01
 * @description:  简单计算函数
 * @author: zhanglu
 * @create: 2022-04-09 09:55:00
 */
object Lu13_SimpleFunction {

  def main(args: Array[String]): Unit = {
    val l01 = List(5, 1, 8, 2, -3, 4)
    val l02 = List(("a", 5), ("b", 1), ("c", 8), ("d", 2), ("e", -3), ("f", 4))

    //求和
    var sum = 0;
    for(e <- l01){
      sum += e
    }
    println(sum)
    println(l01.sum)
    //求乘积
    println(l01.product)
    //最大值
    println(l01.max)
    println(l02.max)
    println(l02.maxBy((tuple: (String, Int)) => tuple._2))
    println(l02.maxBy(_._2))
    //最小值
    println(l01.min)
    println("===========")
    //排序
    println(l01.sorted) //小 -> 大
    println(l01.sorted.reverse) //实现从大到小排序，小 -> 大 -> 翻转
    println(l01.sorted(Ordering[Int].reverse)) //从大到小排序
    println(l02.sortBy(_._2))
    println(l02.sortBy(_._2)(Ordering[Int].reverse))
    println(l01.sortWith((a: Int, b: Int) => a < b))
    println(l01.sortWith(_ < _))
    println(l01.sortWith(_ > _))

  }

}
